package com.netease.financial.common.util;

import android.graphics.Bitmap;

/**
 * Created by wyf on 7/20/15.
 */
public class BitmapUtil {
    public static Bitmap cropCenterBitmap(Bitmap srcBitmap, int newWidth, int newHeight) {
        if (srcBitmap == null) {
            return null;
        }
        int width = srcBitmap.getWidth();
        int height = srcBitmap.getHeight();
        if ((width < newWidth) && (height < newHeight)) {
            return srcBitmap;
        }
        Bitmap desBitmap = Bitmap.createBitmap(srcBitmap,
                Math.max((width - newWidth) / 2, 0),
                Math.max((height - newHeight) / 2, 0),
                Math.min(width, newWidth),
                Math.min(height, newHeight));
        if (desBitmap != srcBitmap) {
            srcBitmap.recycle();
        }
        return desBitmap;
    }
}
